<!Doctype html>
<html>

<head>
    <title>oixan的博客</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html" charset="utf-8">
    <link rel="stylesheet" type="text/css" href="../css/blog.css">
    <script src="./bjs/cryptojs.js"></script>
</head>

<body>
    <div class="head">
        <div class="headnav">
            <div class="naveframe">
                <ul class="navlist">
                    <li>
                        <a href="../index.html">
                            主页
                        </a>
                    </li>
                    <li>
                        <a href="../bloglist.html">
                            博客
                        </a>
                    </li>
                    <li>
                        <a href="../about.html">
                            关于
                        </a>
                    </li>
                </ul>
            </div>
        </div>

        <div class="headtext">
            <div class="headtext1">世界很简单，人类很复杂。</div>
            <div class="headtext2">浮生若梦，寻寻觅觅。</div>
        </div>
    </div>

    <div class="contents-all">
        <div class="contents">

            <div class="frame">
                <div class="title">
                    <h3>python(gui)加密文件功能(博客有密码)</h3>
                </div>
                <div class="dtime">时间：2021-04-20</div>
                <div class="detail" id='detail'>


                    <style>
                        #zhengwen {
                            margin-top: 10%;
                        }

                        .putpsd {
                            border-radius: 8px;
                            width: 300px;
                            height: 100px;
                            margin-left: 4px;
                            padding: 6px;
                            text-align: center;
                            background: linear-gradient(to right top, #a6dad1, #6db8c5);

                        }

                        .putpsd div {
                            display: inline-block;
                            width: 200px;
                            height: 30px;
                            margin: 10px auto;
                        }

                        #inputkey,
                        #btn {
                            width: 200px;
                            height: 30px;
                            border: none;
                            outline-color: #6db8c5;
                            border-radius: 6px;
                            background: linear-gradient(to right bottom,
                                    rgb(255, 255, 255, 0.7),
                                    rgb(255, 255, 255, 0.3));

                        }

                        #inputkey:hover {
                            background: #fff;
                        }

                        #btn:hover {
                            background: #6db8c5;
                        }

                        #btn {
                            box-shadow: 2px 2px 6px #fff;
                        }
                    </style>

                    <div class="putpsd" id="putpsd" style="display: block;">
                        <div>
                            <input type="text" placeholder="输入密码查看博客" id="inputkey">
                        </div>
                        <div>
                            <input type="button" value="确定" id="btn">
                        </div>
                    </div>

                    <div id='zhengwen'></div>

                    
                      



                    <script>
                        const iv = "1231234567abcdab"
                        function getByteLen(val) {
                            var len = 0;
                            for (var i = 0; i < val.length; i++) {
                                if (val[i].match(/[^\x00-\xff]/ig) != null) len += 3;
                                else len += 1;
                            }
                            return len;
                        }



                        function onEncrypto(plaintText, keyword) {

                            if (plaintText.replace(/(^\s*)|(\s*$)/g, "") == '') {
                                alert("输入要加密的内容！");
                                return;
                            }
                            console.log(keyword)
                            if (keyword.replace(/(^\s*)|(\s*$)/g, "") == '') {
                                alert("输入要加密的密码！");
                                return;
                            }
                            while (getByteLen(keyword) % 8 != 0) {
                                keyword = keyword + "\0";
                            }

                            let key = CryptoJS.enc.Utf8.parse(keyword);
                            let encryptedData = CryptoJS.AES.encrypt(plaintText, key, {
                                iv: CryptoJS.enc.Utf8.parse(iv),
                                mode: CryptoJS.mode.CBC,
                                padding: CryptoJS.pad.Pkcs7
                            });
                            encryptedData = encryptedData.ciphertext.toString();
                            console.log(encryptedData)
                            return encryptedData;
                        }

                        let btn = document.getElementById("btn");
                        let detail = document.getElementById("zhengwen");
                        let putpsd = document.getElementById("putpsd");
                        btn.onclick = function () {
                            let plaintText="161f8ca3b9cab10d40207ec3cae3d3d5d06b30e28b82a37d7418eae5569bb100d2debfda458d1d68acdea7d4d63617a4724aca0b7dd2d7d5a43f1e09ab9b081e751dd4a4f85afe94ef71d197525dcdb8b3d2a0d89f2a5979621f6be603af8c961298b0c33f6ebe56c4ced1b699ba5dcef9c778983bbbb3f3e7d195dae16c17473be1f7c7ddf5571e867d01674e939ed46aa097b19aea15aaae9c9cfc093590d9d8589438a62af4a9339fa7a89dfb9e6e7a3ac499df055b03f21f508f310b0039dc74a5a64eccb949aa8e86557adddb8f0db70d9dc544400bfbe10f70745670c9e6478d2c54778fa0062a80ec6a97146a9d11735a27f2bea4a767a750162867523637cac8850e37e2f2706e345387d04a30b1545b38a793c851e0d3318a136492904d12715b8a4d68999467d6102adb9b1914a7e2788b45b6fc53989489198d8941099a84e70f42bf44c14a054957d5cd4a13dc1a3159851b6a897026984f8e870d27941320d8af678887ffb7de4a57fcc0f89d45b970ebecef07a998112579f26f19873303d02e09a5b31ca385fa78d2de95139c25d89328f3b750b0453ba9dc4174fa4fd7b8f8b5378890e429ab60719bab470b0492967038e215cd0e722586b65d025200e2d997fed9b3cd3455231f34762520561801b91818004156e442146c5027fc93cadb240c0d828e6e81f941bd8a097d988d6b06df9a1c677d48de6071953b6e93cf2faa31c149919e7978f59a87ab088b80c54b9fb9bd2ba1adaeb8832e3930fc5fa628235cdf8e42f47233cd2fce8d06464a17f6bdf341e234db85413415ec762302cfb93b7129be4203eb77ca61046e189a0048d3f7fc9a100b583db44d7c813c942e6b1528c8d43821b06c5ca89a0be2d5c98b9fcbeb3af8711cc9c05c02319a250bdc3f6fc802350eedca54a1f8bbea5d634c8f98d425e601a66560113962980365d4ac6a426f780ab75440aa115b67ef2fbd72a4e855833301f542e74e6933551b60e1ea3f10c95102e1b440eb90d170c24adbcb916ed7e524d3bf03fa76f88764bc788dd4f957a988e854a51989a033a2bfa5fcbfc66223bac9f3f35077994e5558a9c3df0b0da15e15b332c09c1403a0a601dbea283e2011f859ab33e1ca8bfdd8b558e1bfd0b6ce736a359c4288898d3e73fd809b4ab36ede3d7c3449fada668766e3b60cc15cc253cb0cd93b17f481c8db8aea6d7bb43b302c77ca58cc4b79682ddba071afeec848b6e3ad15663262abf8ceb5d043b21bc2d1fd29d32ca8084156a48d7c531f59b3a1ae06c8ac4bfdb44aafe1009bc3b5fd11450d0c431301cda6e4fb198cecfd5e741380ee5b0b5157cc918c6c85dccfff26868a16992df3e45459e1c8de7fb8826997d65c38faffa34c43502624dc53c9b549e0915cb1b79f688672fd5a8e01f773a35e4842175fb33d51fdd432f631832acc89ba53176471c5ec3416434cd6e5f7960c995ad90563f70c30860f1060d231ed42a1b90acdd8b7ff8e8bdcb4102a3b9636b18f102706e64d743b3051edaf210583847933d4db4642a5e873c5efcb8f67d987b59f125f9ef00dfba037125148621b5aa73bee30f671dc62f94127a09ff05a5884e413d959648dbdc31d3a6cffc2c88871259d01fc786d002651b21d4a05a110d9a7f853c53c0fd6e7aeb7b536953ead6710c7245a255bc6ec78ac12817b0554219b958b9c6bc635547af0d64df89f64c591374222c6bc5e8481637f83e956e21317ad1a65d3d39ebce72997f8cdc44ee85cbe5df76844f7de6b79c5f62b6f41e73eb83889147e79e0d9c99f873c6b05f7a26093f5d643a768ba79c41df9752ad9c5575dc7263e94ae66fe66768e8f111cb8065c6d50daed4b46fde4b0a59c5ea8e243ce0ec68d9211c064c3c9e2023a895c1b6b49c7fbd28ba68b1e2ad1d23626da915cf84761e6ce4f145e8a4a3868d6b47fdd0cc8f6dad01fa95e8d3770bc11e47395fed95ba37fde6431e122395b8a312df10ee2bd7e407460a1644f3adfeac397875dd524c654459577b59364b5de1f9b6a4ce64f09f6faa26641e0eeef82ed25ffd72c0b8226282fd07f704976aa791c274bd7ea855ed9dbd5a9c69189eceec16be543fa184219a696187339807dcc2a18ddb43b0e3a70d9860d6f8f0eed30d6f046f47d4dfb9d747faa37a0ed4c64e4c85b97c38dd2e36c2ed82022fc10f744203c84d65055ec966ea9f6f5f0ffe7e2274500e6309398ba9de5f67d31aa5725640d8cced2168e5232bb3b15c55fff991c32031e47e069a3bd069bfb859001513544adb0194e6e8309c2e9afc4f111fb85873a6e092a47df43c876d5198111d99e392dd54ee5f82addb1d96694c3b89ae8fbed723ab2da8ba9d11eec5112969f39049be90b3e594632a36bfe1ee138362fc7038baaa363a5628dfd19c7a9b440e6e72fb3ba67f88f3173e7ecc88725b3efb99da2f3845f954ca46b3b934b5e1041f65aac864b5cc8041b9a6d7b079963811c6f5a059a25f2b9e0f0ffbe0a1a74963622622c9c70c6561c9bf29876adeffa5228c7c917091bdb79c0d8ab7632b5b7c32cb45e6bc6c203b17107f3ee49bf023a40617d90b797d769bc705e800d8bbb119d82a131dbc57f4c77013f125b15981ee49a6c9016d578c15dedd280590727ac75889932c2372a2560935b725af753497533866fb49dfe1eff0ecaa55787af904058da801a615cfa2336de94f1565be4bad923bc4228a0758abdcc34411a78ab7ef15d7010df151a502e8a8643bb3e47ad191200e4e9ec3d02d73b3b94519cfd4d6749f6ab70369ffb4550bacdbac30f395f15ebeaeb4cf313442206951c8d7a4f5e3a2240d68e64257f2032e8ee0835641152640d42e4785f1240d4926cacadfc8e5dd2b6b1d07dd1a3faad35c9aab9d5cfdb1535ee7b4a5f094a371e5e7450022692600604f9aff9694958c80b1d59b3eb98cd98f8b069d06fbe55337c93c87f0f3fe39b148d79b24beeb125fcabc58662c15e8c3ab0d463f406a0497456ad8b67a403dcb4d4330cd9693d2b51440f3ce624d387d6f831606f1af117ffc4772b390b01856a4d90217a7a3a82854aff9225e062233a98ff91ddb35ab344d3b1e6518bb094a03f482e647b7322d8bc1b2ae089e30c66c56cef42ca287a62226203347aa187bad2028283f8314ece2b9b464895f48dd7a174e20513e1936606177f8f6ec7a3c7f62907e1676132916b696d59c4b140b039b514620a53027cfb757430275b9a203963f3688ae1c0e74ded2112a0c60b5b28e9fa13a45c01ac2a0fb2f6d8eb298665a9212245f821202407b76eabe501c1600d7ae90fd5f1fee8ac53981476dad03b9466a9b5f66e28fbf651bd776d76a2dffa8cd5608a37701ad85a67259db83c3ebf007e84d7f9e533a3070f7590c3455c17a0c4aa202a54ab385f2159d6ba0a1a988c787d2c7965fa16fa7c440e7b87d8c9355c5ba0e338399cf2f5a9b55915528ecddbf57dcb9b603e4c9c139981d013d3d3f9a17663d198e7c9c3990f20ec31ea8d7042ad8e4dd476275b5e6ccf67beb19945b0866be9e8f1d70324a5c91539763655c86b0d9316b3e7baac0e19e15eefcf2007d75ab0357f5fb725932f855f5772b22218e05cab2842afe7e004bc069d931804b4a84ead6d4084c1045233f80d42e43a30d7198d85188af6a6a6c53d4a9f7c8c2286c4616cbd59ec90b512838948e3fa139e434905c910253c4a6eeffb6940643ddb855afddc86f1bfb823f7f89a9fd70f2348896fe4277d2e9481a0c8e38c73688a6b915b65786c2602beb5c913d0248cea7dfcb09726c843a6abfb566b437cf630949df44f59c18e3d53b6154522e6b7afbc9ef933d198f16f4d04c1b03da81f98036d4dec576e0c09dca27b6cf13a6c7d4d94235f0605790a6599d0a08bf32048ac62807851aa52679a4f6250a568e0f1b8efa1b31422bd8e02288f191e7d7bc71fe02770b11a238fc40eb6d2485b286a29e773e7efc212ee10247a4465ff654afdd5b3d2a505187b80cab986acdcb49ec11b719f3e2627a5bea4947a9f932d3d93364c6b39a0bfb422708950f5fd917dc3f47bd48555ba7e52f71ca674bcc6d8652ab610dde4f8c6e79ecf146a680a2417bd181e4e1097ea4229d16289671ac7926f8f57a2ee255545827af62c856bebc3705cb40a67beb5f6b4adeeb201badec9e65ff5fd0389c48f1db30970c6d3e4b477f7ab7a44ea964cd76d8e8fd1ee824885cd703840934838d9ce3fba765d3410e2fb398397cf5acfba9d2ec5677b0552e82d39a345f5ac579b9a6f20c41cd0ac791c7705e8c1e01f1846517fadc069d24c2106ebf3a3d6c651f3d2aced8b58dbb04ed96c4ca2c0abfcd947b863f668665619247bfe9f216ad742bf3a00b91b822e532d08b206cfcc021d50d3a87aa1d92ab71ca4033e5c71edfb9f29e1892b69df333d930b20a49cda65be034e7fa167f9eaf5fd4b6d0e5a34ce72a82e6d35bcd7b0f8ba486365aca78c28183e0c33a83eb0642d3c8c2d70f1fb3ff030d97a85307e9f8348767adf050a4022071936f6e87d9675840555b6bd9eb302120d2ede48e8fe97849ea56329b320178fcd3b5d4b6c5878079d8930ce58355462370f0616872dec1ef26ce3b2c690f2507f970764435d88b912deba652e488af2c084eb47f0eb21ff6e81d423fad476df117966120d07750f81676082c67388abf07b82e25dc3e0ee110738a8efe1962c349960c3e77c04400b7bea57f5e9a13d6664e9734eec0a4263a0b5bdd7ff7f7a1ebd49a5e486425934c95a4b0560db42a5fc6bd64c7815a3fe58a175e8d0c19ca42e6919b84d6f330787cf7f294ef5404d1f3eaf4a804cfcd82042933a421695713fa80c0b7ae0aea0510be0d03581b800eca23489536a11f3db85cd91aab6ab5c06d8aa4cef1fbc6c5369190e99b640a284399871e3a084d12f8464a5795f40234f5e233a2bab64172efab304b590fb7e7454d7d9ec7287b6b452369bc26465e086d18710ac97c82f7459c7c22a1cdc3a335319e60c578c19293f8a399c592ab0e0f2641a572a3f16a4335fba796381613163cb42bb469a017c5113a93f62268ad289cf530d39c10699ce597a92294d129b5322a25dff75ed61fd4c1d6781deaaca79286ae173a260c231d75002545902fe59b3555a81c6569f3b916b7a228ebf251f031726a907905261769cd48846e71a05efc93b2773186b55f21dda5c184ba4000f3c102a8e8bd2950ca003cabb3f11205f495633829b87d7388e4b5b69fee5eadc396522fe799604d26f43456e4b52b3b3106ac24793f909d53d5cf4cbb506792e24381aadb4f101289563db1e2611d9535f05fb50ef6d3be1bd49becf853076cdacdf58e33f4815523d62e7b3bba77371904542b3891b3a59f5cbaf054e6748118bd230f564f3089c1493401b3d6ebad11dd1ed6eb68f90709f6b4fbf6b9fc33e26341439058e67be9966b834f9b2f06f77bbca6ff48c631f3f63be1f3b1aea6d3f46245ac1c7db1cc3da8a22f17091283aa9ac5005fb882c4796db6e9b64e509ab52c39f6330dd7804efb470c1c0d524941d0ebb10ad98b45e293736bf59623fcfbec73f7720c66e7187b11f641b2c42ff7b1706a585d9f23074877427e9e3e409602012ea77d6fe567b84f92a9ed541da72b676e1a6fbd8c5391e6cdb2b5c677ce1d2902b7b2481b726fb6421f45b1d0c3f8ad793d07cb8556d3b727ae546aa17d9199659def6841ac1e4cefc5f0122082ea952541077431c7546cb765349b65b22e8eab2d57006fa9fb359a5b13429533a1b861277365baf66d5c5716b9b284b5de0baa26eb805ea0d2e1da7bc18b0772ea9777685704cdcbe7c6abf6e51116bf0c614179db412dc8daffe96f72f89cd94b014f033d88a35a85afc61e75aa918156c46b847a34e283be70d1e780679eed27c082f9d8d26336bdf5cf9f207301b1a1dd0c8ef33aa7b1c4a5a0120474d75f8ef92a36d994c30076e6d85ef5a528a78aa40f33911757b38ddcd7004e0d2019f61fa9e9e8e945ff6e55fa28a61e5bee0f8b68bba6bf621ae66d9195a62ed384535969e260675b3392203512a6279580f633f6b3384f436d28c961d4c2581d6512598db0aa1404bcc001cecee4e6debf7df03151a7b587ae87387f7ef3c0cfff3eb0f3300a51c1d2f2f9f1ca3d02adb68144ba55c348c8044d3e7125c9590188a0923c5ad5cb56a72386180379f66b50a3b83a7464ba780f05ae7707c598a6f037b3a1d22667c8a14727f9b7bf0280406d886814431c4cd3f011e4ada51c040b416861ecee33f261a485ff9f073cca7d53e18e6397e5329e471b36577210d70545f9c7a280d8a079eceab6e10fc70d69a6c04b65aa0e2692749a80e96d375eaad5dcc4153a6e00bb615d0ab2b1ab9c190b5b4f21fcf22414c11646d3224b3044690224b2d98ca40f59f9070ee3d4212f7ec8a8edb6f879e310ab6e2c04e8ca2f304225de940e345690fc68fb5b0cae43fe29d47cffeb2fd5b9e8ca6b32d1f7a86926162a0b428c02c86991a9d125c38dc822bf25565ee143c4c78432247363eebe04c71e559192e4f24e5c92c7ede27b191daa54289b9588f8f733adc948d0cdd2a50e881743eb247098547c168503a679aacca159a9554b052bc416869686e3ddbbcf10648341c1b77d6557e14b10a4566468fb50c0e58db491e912127bb446605fd7fc6b899ae1689bf8195e2aa547c8593a0f3cac8f51fdcbabdb2f01caab6175e8251334854c95d572f2ba3530eef1980213e0a34b60399bc07459cc6038771098e06e8bfd47e9fb76efcf53f4ff8928378dd31530e24d5f65a89c00f003ee7de29a1205a85bb880bd031b5d1974afe4f51a064adee4edece0f1e02bc8e02f3bb6455601c428b103d36f6c65559b0c0232c50efb3253f1889006ccaa94fcf68eaf49552f68b6068dc2b53f74a7bcb2667ba043b6bcf724fb551335bb70f727f3c559cc6e79b576fb9a88b18f8ef42c88515950677a6bbd2ffee73110c13f8e7aaa59a5659d1d1c6af0d6b6933a70eeb1e9acc7e395e582670aa06a6ea8a055910756be8c08fb337bb34bb8141e29487d2aa781b32bde688525559bd36cb04e3b9f5bbeab5848e01f6a4dee670b0eb8d2ae1a11176ce5f41fc49b627439498430ba10ec22267b2e0e4ce1f7f61ef8d1ed24fa1c8e3689b48b6222fd5e3cfa4db52aa9e6631d501ce84a2be7aa95072bfb31199a7ea1a9f1555cfbaf04567dc9ca3422349dc50da1d45fb056b2fe2809a4b485b4979922bbdeaa1b184b50b3c150471b5d9120cba79077a30e2d80451708bd3a533c64d57e2544391e16715dc32536f3ad5360783bef1cff77877499a318da4d0ec7086830524c76d045b91f138500ca7c504abc8f84797d2164e32e7eea70fe33b4d51fad08e7e07b00a7994cab4673b5134ad4931b2d3da4a4169a1cb89475d63eff491460145195fa515f950bded8c27b7a9dcaf2bb34128e3284b0f1af0aecb1359998a6b495432a664df45648196450e2a3f28a1890bc5c981fad75797c62b462918f5e41c716c542a59da551b735632b0e8ab1cf817c42916373bda47f5e1a17ce47749ff087141881529743fef81ced6e7a57c2bcd064d23d9be58b2c299c6a4be31de9483569ac7e4fd6f677cb33acfe85512d23a486ae919d10ffe6c0849fbfedfdc610b8bb26876a6e213d249051eddd113cb3ac6d978ded603804d304470a7a26f8f054936c064cb66d2f18291bd3a39f2973a478f2742a8fee921157ebc63c9b83b8f26bbaa4d3184d9c789c2a0fc3b4ae6fe0f1c533cf9d62a36c42fc2dbfff0d318cbcc45326af8c1e3029b1976ed6d36bac86889b53b41f76c6c89530b99e3fcb3825e140fc823d7bacb9c638ae007f81401774d176c00725de8e1a338f0ef4cfd545f6268b24bbffa6b39e6c3a68eebe28f766259818a3f5f50ad4bb0a2f12b6b354fe0472a7d8c7186c5dac2c0f9bd60e500225dd15d932f5eb700014afa4a6c30790d7333a64b54f13ad6b9f7123b2dbeb5d63d0f7f6ef2d7dc3637cfcd31b26003987154ff0db1ee112b15b4b3e438d016047b6c08ad5ab80ee8c5360e2e4dbc2033498138d47c6849a4a479eb107c65274f3f8d11584df5995202b5d773bdb49c56bf3fd5a6cf3fa02422a6014c4ad0578884fd21de406c"
                            let keyword = document.getElementById("inputkey").value;

                            let divstr = onDecrypto(plaintText, keyword);
                            if(keyword.replace(/(^\s*)|(\s*$)/g, "").length>0){
                            if (divstr) {
                                putpsd.style.display = "none";
                                console.log(divstr)
                                detail.innerHTML = "<p></p>" + divstr;
                            } else {
                                alert("密码错误!")
                            }
                            }

                        }

                        function onDecrypto(encryptedData, keyword) {

                            if (encryptedData.replace(/(^\s*)|(\s*$)/g, "") == '') {
                                alert("输入要解密的内容！");
                                return;
                            }
                            if (keyword.replace(/(^\s*)|(\s*$)/g, "") == '') {
                                alert("输入要解密的密码！");
                                return;
                            }
                            while (getByteLen(keyword) % 8 != 0) {
                                keyword = keyword + "\0";
                            }

                            let key = CryptoJS.enc.Utf8.parse(keyword);
                            let encryptedHexStr = CryptoJS.enc.Hex.parse(encryptedData);
                            let encryptedBase64Str = CryptoJS.enc.Base64.stringify(encryptedHexStr);

                            let decryptedData = CryptoJS.AES.decrypt(encryptedBase64Str, key, {
                                iv: CryptoJS.enc.Utf8.parse(iv),
                                mode: CryptoJS.mode.CBC,
                                padding: CryptoJS.pad.Pkcs7
                            });

                            let decryptedStr = '';
                            try {
                                decryptedStr = decryptedData.toString(CryptoJS.enc.Utf8);
                            } catch (e) {
                            }


                            return decryptedStr
                        }
                    </script>




                </div>
                <a href="javascript:void(0)" onclick="showPg()">返回</a>
            </div>


        </div>
    </div>
    <div class="footer">
        <div class="footertext">©2018,oixan博客</div>
    </div>
    <span id="backtop" onclick="topFunction()">返回顶部</span>
</body>
<script src="../js/fanhuiye.js"></script>

</html>